package org.shan.lf.common.utils;

import org.springframework.util.ResourceUtils;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;

/**
 * Created by amanda.shan on 2019/7/9.
 */
public class SmartResourceUtils {


    /**
     * 读取资源文件 读取String
     *
     * @param path classpath:templates/b_dfd.txt
     * @return
     */
    public static String readString(String path) throws FileNotFoundException {
        File file = ResourceUtils.getFile("classpath:" + path);

        Reader reader = new FileReader(file);
        StringBuffer buffer = new StringBuffer();

        char[] chars = new char[100];
        int read = 0;
        try {
            while ((read = reader.read(chars)) > 0) {
                buffer.append(chars, 0, read);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

        return buffer .toString();
    }
}
